#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import sys

execfile(os.path.join(sys.path[0], "framework.py"))

from oriolus.docker.storages.memorystorage import MemoryStorage
from oriolus.pith.packets.packet import FilePacket
from unittest import TestCase, TestLoader, TextTestRunner

class TestMemoryStorage(TestCase):
    def test_add(self):
        test_packet = FilePacket("./testdata/testpackets/test_packet-1.2.3.4.zip.ori")
        storage = MemoryStorage()

        self.assertEqual(0, len(storage.entries))

        storage.add(test_packet)

        self.assertEqual(1, len(storage.entries))
        self.assertEqual(test_packet, storage.entries[0])

    def test_remove1(self):
        test_packet = FilePacket("./testdata/testpackets/test_packet-1.2.3.4.zip.ori")
        storage = MemoryStorage()

        self.assertEqual(0, len(storage.entries))

        storage.add(test_packet)

        self.assertEqual(1, len(storage.entries))
        self.assertEqual(test_packet, storage.entries[0])

        storage.remove("test_packet-1.2.3.4")

        self.assertEqual(0, len(storage.entries))

    def test_remove2(self):
        test_packet = FilePacket("./testdata/testpackets/test_packet-1.2.3.4.zip.ori")
        storage = MemoryStorage()

        self.assertEqual(0, len(storage.entries))

        storage.add(test_packet)

        self.assertEqual(1, len(storage.entries))
        self.assertEqual(test_packet, storage.entries[0])

        storage.remove("test_packet")

        self.assertEqual(1, len(storage.entries))
        self.assertEqual(test_packet, storage.entries[0])

if __name__ == "__main__":
    suite = TestLoader().loadTestsFromTestCase(TestMemoryStorage)
    TextTestRunner(verbosity=2).run(suite)